package com.animee.tally.util;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.NonNull;

import com.animee.tally.AboutActivity;
import com.animee.tally.HistoryActivity;
import com.animee.tally.MonthChartActivity;
import com.animee.tally.R;
import com.animee.tally.SettingActivity;

public class MoreDialog extends Dialog implements View.OnClickListener {
    Button aboutBtn,settingBtn,recordBtn,infoBtn;
    ImageView errorIv;
    public MoreDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_more);   //绑定布局
        aboutBtn = findViewById(R.id.dialog_more_btn_about);  //查找元素
        settingBtn = findViewById(R.id.dialog_more_btn_setting);
        recordBtn = findViewById(R.id.dialog_more_btn_record);
        infoBtn = findViewById(R.id.dialog_more_btn_info);
        errorIv = findViewById(R.id.dialog_more_iv);
        //设置点击事件
        aboutBtn.setOnClickListener(this);
        settingBtn.setOnClickListener(this);
        recordBtn.setOnClickListener(this);
        infoBtn.setOnClickListener(this);
        errorIv.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_more_btn_about:
                // 跳转到关于界面
                Intent it1 = new Intent(getContext(), AboutActivity.class);
                getContext().startActivity(it1);
                cancel();
                break;
            case R.id.dialog_more_btn_setting:
                Intent it3 = new Intent(getContext(), SettingActivity.class);
                getContext().startActivity(it3);
                cancel();
                break;
            case R.id.dialog_more_btn_record:
                Intent it2 = new Intent(getContext(), HistoryActivity.class);
                getContext().startActivity(it2);
                cancel();
                break;
            case R.id.dialog_more_btn_info:
                Intent intent = new Intent(getContext(), MonthChartActivity.class);
                getContext().startActivity(intent);
                cancel();
                break;
            case R.id.dialog_more_iv:
                // 让当前对话框消失
                cancel();
                break;

        }
    }
    /* 设置Dialog的尺寸与屏幕尺寸一致*/
    public void setDialogSize(){
        Window window = getWindow();   //获取当前窗口对象
        WindowManager.LayoutParams wlp = window.getAttributes();   //获得窗口对象的参数
        Display d = window.getWindowManager().getDefaultDisplay();//获取屏幕宽
        wlp.width = (int) (d.getWidth());//宽度按屏幕大小的百分比设置 ;d.getWidth()这个方法已废弃
        wlp.gravity = Gravity.BOTTOM;
        window.setBackgroundDrawableResource(android.R.color.transparent);  // 设置窗口的背景资源
        window.setAttributes(wlp);

    }
}
